package com.xiaoli.algebra.test;

import java.util.Date;

import junit.framework.TestCase;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;

import bsh.Interpreter;

import com.xiaoli.algebra.AlgebraLexer;
import com.xiaoli.algebra.AlgebraParser;

public class AlgebraTestCase extends TestCase {
	public void testAdd() throws Exception {
		String a = "1+3+4";
		CharStream input = new ANTLRStringStream(a);
		AlgebraLexer lex = new AlgebraLexer(input);
		CommonTokenStream stream = new CommonTokenStream(lex);
		AlgebraParser p = new AlgebraParser(stream);
		p.addExpr();
	}
	
	public void testBeanShell() throws Exception {
		Interpreter i = new Interpreter();  // Construct an interpreter
		i.set("foo", 5);                    // Set variables
		i.set("date", new Date() ); 
		Date date = (Date)i.get("date");    // retrieve a variable
		// Eval a statement and get the result
		Object eval = i.eval("bar = foo*10");             
		System.out.println( i.get("bar") );
		System.out.println(i.eval("1+3+4*4"));
	}
}
